﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Clarius.Silverlight.Streaming.Library.Operations
{
    internal class DownloadFileOperation : SilverlightStreamingOperation
    {
        File file;

        internal DownloadFileOperation(File file)
        {
            this.file = file;

            base.Initialize(file.Parent.Parent);
        }

        protected override void HandleErrorFromHttpStatusCode(System.Net.HttpStatusCode statusCode, string errorText, Exception ex)
        {
            throw new SilverlightStreamingException(errorText, ex);
        }

        protected override WebRequest GetWebRequest()
        {
            WebRequest request = WebUtil.GetWebRequest(accountManager.Account, "/" + file.Parent.Name + "/" + file.Name);
            request.Method = WebUtil.HTTP_METHOD_GET;
            return request;
        }

        protected override object ParseWebResponse(byte[] responseBytes)
        {
            return responseBytes;
        }

        protected override object ParseWebResponse(string responseText)
        {
            return responseText;
        }
    }
}
